home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / winsrc17.zip / MAINFRAC.C < prev    next >
C/C++ Source or Header  |  1992-02-01  |  16KB  |  597 lines

  1. /*
  2.    non-windows main driver of Fractint for Windows -
  3. */
  4.  
  5.  
  6. #define PUTTHEMHERE 1        /* stuff common external arrays here */
  7.  
  8. void win_cmdfiles();
  9.  
  10. /* from MSC's <dos.h> */
  11. #define FP_SEG(fp) (*((unsigned _far *)&(fp)+1))
  12. #define FP_OFF(fp) (*((unsigned _far *)&(fp)))
  13.  
  14. #include "fractint.h"
  15. #include "fractype.h"
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <search.h>
  20. #include <string.h>
  21. #include <float.h>
  22. #include <ctype.h>
  23. #include <time.h>
  24.  
  25. int cmp_line(), pot_line();
  26.  
  27. LPSTR win_lpCmdLine;
  28.  
  29. extern int time_to_restart;
  30. extern int time_to_reinit;
  31. extern int time_to_quit;
  32. extern int time_to_load;
  33. extern int time_to_save;
  34. extern int time_to_print;
  35. extern int time_to_cycle;
  36.  
  37. extern char FileName[];
  38. char string004[2];
  39.  
  40. unsigned char textcolor[27];
  41.  
  42. extern int xdots, ydots, colors, maxiter;
  43. extern int ytop, ybottom, xleft, xright;
  44.  
  45. int fractype;
  46. extern int invert;
  47.  
  48. double ftemp, xxmin, xxmax, yymin, yymax;
  49. long fudge;
  50. double xfudge;
  51.  
  52. long xvalue, yvalue;
  53. extern long lm, linitx, linity;
  54. int maxit, bitshift;
  55. extern int color, row, col;
  56.  
  57. int calc_status; /* -1 no fractal            */
  58.          /*  0 parms changed, recalc reqd   */
  59.          /*  1 actively calculating        */
  60.          /*  2 interrupted, resumable        */
  61.          /*  3 interrupted, not resumable   */
  62.          /*  4 completed            */
  63.  
  64. extern int reset_periodicity;
  65. extern int cpu;
  66. extern int kbdcount;
  67. extern int max_kbdcount;
  68. extern int show_orbit;
  69. extern int orbit_ptr;
  70. extern int periodicitycheck;
  71. extern int debugflag;
  72. int integerfractal;
  73. extern int distest;
  74. int oktoprint = 0;
  75. extern int bitshiftless1;
  76. char usr_stdcalcmode, stdcalcmode;
  77. int  usr_distest;
  78. int usr_floatflag, usr_periodicitycheck;
  79.  
  80. long creal, cimag;
  81. long delx, dely, delx2, dely2, delmin;
  82. long xmin, xmax, ymin, ymax, x3rd, y3rd;
  83. double  dxsize, dysize;        /* xdots-1, ydots-1        */
  84. double delxx, delyy, delxx2, delyy2, ddelmin, xx3rd, yy3rd;
  85. double param[4];
  86. double potparam[3];
  87. int diskvideo, savedac;
  88. long calctime;
  89. int mode7text, textsafe;
  90.  
  91. #define MAXLINE  2048
  92.  
  93. long   far *lx0, far *ly0, far *lx1, far *ly1;
  94. double far *dx0, far *dy0, far *dx1, far *dy1;
  95. extern double far *temp_array;
  96.  
  97. extern unsigned char trigndx[4];
  98.  
  99. unsigned char dacbox[257][3];
  100. double plotmx1, plotmx2, plotmy1, plotmy2;
  101. extern int MPOverflow;
  102. int dotmode;
  103. extern int pot16bit;
  104. int andcolor, resave_flag;
  105. extern int timer_interval;
  106. extern int active_ovly;
  107.  
  108. int extraseg;
  109. int timedsave = 0;
  110. int disk16bit = 0;
  111. extern int initbatch;
  112. float far initifs3d[32][13];
  113. float far initifs[32][7];
  114. extern unsigned char readname[];
  115. unsigned char MAP_name[40] = "";
  116. int rowcount;
  117. int adapter;
  118. extern int showfile;
  119. extern int initmode;
  120. extern int overlay3d;
  121. extern int display3d;
  122. extern int filetype;
  123. int comparegif = 0;
  124. int diskisactive = 0;
  125. extern int initsavetime;
  126. int saveticks = 0;
  127. int savebase = 0;
  128. int zwidth = 0;
  129. extern int (*outln)();
  130. extern int out_line();
  131. extern int outlin16();
  132. static int call_line3d();
  133. extern int line3d();
  134. extern int gifview();
  135. extern int tgaview();
  136. int hasconfig = 0;
  137. FILE *dacfile;
  138. int mapset = 0;
  139. int reallyega = 0;
  140. int loadPalette = 0;
  141. int compiled_by_turboc = 0;
  142.  
  143. int     sxdots,sydots;
  144. int     sxoffs=0,syoffs=0;
  145. int     viewwindow=0;
  146. float   viewreduction=1;
  147. int     viewcrop=1;
  148. float   finalaspectratio;
  149. int     viewxdots=0,viewydots=0;
  150. extern int filexdots, fileydots, filecolors;
  151. int frommandel;
  152.  
  153. int debug_fastupdate;        /* debugging - update every pixel if set */
  154.  
  155. int onthelist[100];        /* list of available fractal types */
  156. int CountFractalList;           /* how many are on the list? */
  157. extern int CurrentFractal;        /* which one is current? */
  158.  
  159. int Printer_Resolution, Printer_Titleblock, Printer_SFrequency;
  160. int Printer_SetScreen, Printer_SStyle, Printer_Type;
  161. int Printer_ColorXlat, Printer_SAngle, LPTnumber;
  162. int EPSFileType, Print_To_File, Printer_CRLF;
  163. int ColorPS;
  164. int Printer_BFrequency, Printer_BStyle, Printer_BAngle;
  165. int Printer_GFrequency, Printer_GStyle, Printer_GAngle;
  166. int Printer_RFrequency, Printer_RStyle, Printer_RAngle;
  167.  
  168. int tabmode, video_type, no_color_text;
  169.  
  170. long    l_at_rad;        /* finite attractor radius  */
  171. double    f_at_rad;        /* finite attractor radius  */
  172.  
  173. int Distribution = 30, Offset = 0, Slope = 25;
  174. long con;
  175.  
  176. int active_system = WINFRAC;    /* running under windows */
  177. extern int win_display3d, win_overlay3d;
  178.  
  179. int iit = 0;
  180. int vesa_detect;
  181. int far videotable[2];
  182. int release;
  183. extern int win_release;
  184. char busy;
  185. int started_resaves = 0;
  186. int gotrealdac = 1;
  187. void    (*outln_cleanup)();
  188. extern int fpu;
  189. int svga_type = 0;
  190. int TranspSymmetry;
  191.  
  192. compare_fractalnames( const void *element1, const void *element2)
  193. {
  194. int i, j, k;
  195.     j = *(int*)element1;
  196.     k = *(int*)element2;
  197. for (i = 0; i < 100; i++) {
  198.     if (fractalspecific[j].name[i] < fractalspecific[k].name[i])
  199.         return(-1);
  200.     if (fractalspecific[j].name[i] > fractalspecific[k].name[i])
  201.         return(1);
  202.     if (fractalspecific[j].name[i] == 0)
  203.         return(0);
  204.     }
  205. return(0);
  206. }
  207.  
  208. fractint_main()
  209. {
  210. int i, k;
  211. double temp1, temp2;
  212. double dtemp;
  213.  
  214. outln_cleanup = NULL;        /* outln routine can set this */
  215.  
  216. CountFractalList = 0;
  217. for (k = 0; fractalspecific[k].name != NULL; k++)
  218.    if (fractalspecific[k].name[0] != '*' &&
  219.        (fractalspecific[k].flags & WINFRAC) != 0 &&
  220.        CountFractalList < 100) 
  221.             onthelist[CountFractalList++] = k;
  222. qsort(onthelist,CountFractalList,2,compare_fractalnames);
  223. CurrentFractal = fractype;
  224.  
  225. lx0 = (long far *)&temp_array[0*MAXLINE];
  226. ly0 = (long far *)&temp_array[1*MAXLINE];
  227. lx1 = (long far *)&temp_array[2*MAXLINE];
  228. ly1 = (long far *)&temp_array[2*MAXLINE];
  229. dx0 = (double far *)&temp_array[0*MAXLINE];
  230. dy0 = (double far *)&temp_array[1*MAXLINE];
  231. dx1 = (double far *)&temp_array[2*MAXLINE];
  232. dy1 = (double far *)&temp_array[2*MAXLINE];
  233. extraseg = FP_SEG(dx0);
  234.  
  235. restoredac();        /* ensure that the palette has been initialized */
  236.  
  237. win_cmdfiles();                /* SSTOOLS.INI processing */
  238.  
  239. initmode = 1;                           /* override SSTOOLS.INI */
  240.  
  241. release = win_release;
  242.  
  243. dotmode = 1;
  244. diskvideo = 0;
  245. usr_distest = 0;
  246.  
  247. max_kbdcount=(cpu==386) ? 80 : 30; /* check the keyboard less often */
  248.  
  249. /* ----- */
  250.  
  251. debug_fastupdate = 0;
  252. calc_status = -1;
  253. resave_flag = 1;
  254. strcpy(FileName,"Fract001");
  255. if (showfile != 0) {
  256.     strcpy(readname, FileName);
  257.     }
  258. else {
  259.     if (strchr(readname,'.') == NULL)
  260.      strcat(readname,".gif");
  261.     strcpy(FileName,readname);
  262.     time_to_load = 1;
  263.     }
  264.  
  265. if (debugflag == 23232) {   /* check for free memory */
  266.    char temp[50];
  267.    sprintf(temp," %d bytes of free stack space",stackavail());
  268.    stopmsg(0,temp);
  269.    }
  270.  
  271. if (debugflag == 70) fpu = 0;
  272.  
  273. /* ----- */
  274.  
  275. time_to_quit = 0;
  276. if (debugflag == 23232) /* give the Windows stuff control first */
  277.     getakey(); 
  278. if (time_to_quit)
  279.     return(0);
  280.  
  281. reinit:
  282.     time_to_reinit = 0;
  283.  
  284.     savedac = 0;             /* don't save the VGA DAC */
  285.  
  286.     for (i = 0; i < 4; i++) {
  287.         if(param[i] != FLT_MAX)
  288.             fractalspecific[fractype].paramvalue[i] = param[i];
  289.         else
  290.             param[i] = fractalspecific[fractype].paramvalue[i];
  291.         }
  292.  
  293. /*  Not used, MCP 8-6-91
  294.     ccreal = param[0]; ccimag = param[1]; */ /* default C-values */
  295.     frommandel = 0;
  296.  
  297.     if (xxmin > xxmax) {
  298.        dtemp = xxmin; xxmin = xxmax; xxmax = dtemp;} 
  299.     if (yymin > yymax) {
  300.        dtemp = yymin; yymin = yymax; yymax = dtemp;} 
  301.  
  302.     ytop    = 0;
  303.     ybottom = ydots-1;
  304.     xleft   = 0;
  305.     xright  = xdots-1;
  306.     filexdots = xdots;
  307.     fileydots = ydots;
  308.     filecolors = colors;
  309.  
  310. restart:
  311.     time_to_restart = 0;
  312.  
  313.     if (calc_status == -99)
  314.         calc_status = 2;            /* force a recalc */
  315.     else
  316.         calc_status = 0;            /* force a restart */
  317.  
  318.     maxit = maxiter;
  319.  
  320.     if (colors == 2 && (fractype == PLASMA || usr_stdcalcmode == 'b'))
  321.         colors = 16;         /* 2-color mode just doesn't work on these */
  322.  
  323.     andcolor = colors-1;
  324.  
  325.     debug_fastupdate = 0;    /* turn off debug-mode screen updates */
  326.     if (debugflag == 6666)
  327.         debug_fastupdate = 1;
  328.  
  329.     /* compute the (new) screen co-ordinates */
  330.     /* correct a possibly munged-up zoom-box outside the image range */
  331.     if (ytop    >= ydots) ytop    = ydots-1;
  332.     if (ybottom >= ydots) ybottom = ydots-1;
  333.     if (xleft   >= xdots) xleft   = xdots-1;
  334.     if (xright  >= xdots) xright  = xdots-1;
  335.     if (xleft == xright || ytop == ybottom) {
  336.         }
  337.     if (xleft > xright)
  338.         { i = xleft; xleft = xright; xright = i;}
  339.     if (ytop > ybottom)
  340.         { i = ybottom; ybottom = ytop; ytop = i;}
  341.     temp1 = xxmin;
  342.     temp2 = xxmax - xxmin;
  343.     xxmin = temp1 + (temp2 * xleft )/(xdots-1);
  344.     xxmax = temp1 + (temp2 * xright)/(xdots-1);
  345.     temp1 = yymin;
  346.     temp2 = yymax - yymin;
  347.     yymin = temp1 + (temp2 * (ydots - 1 - ybottom)/(ydots-1));
  348.     yymax = temp1 + (temp2 * (ydots - 1 - ytop   )/(ydots-1));
  349.     xx3rd = xxmin;
  350.     yy3rd = yymin;
  351.     xleft   = 0;
  352.     xright  = xdots-1;
  353.     ytop    = 0;
  354.     ybottom = ydots-1;
  355.  
  356. /*
  357.     delxx = (xxmax - xxmin) / (xdots-1);
  358.     delyy = (yymax - yymin) / (ydots-1);
  359.     delxx2 = delyy2 = 0.0;
  360.     ddelmin = fabs(delxx);
  361.     if (fabs(delyy) < ddelmin)
  362.         ddelmin = fabs(delyy);
  363. */
  364.  
  365.     dxsize = xdots - 1;  dysize = ydots - 1;
  366.  
  367.     if (calc_status != 2 && !overlay3d)
  368.         if (!clear_screen(1)) {
  369.             stopmsg(0,"Can't free and re-allocate the image");
  370.             return(0);
  371.             }
  372.  
  373.     dxsize = xdots - 1;  dysize = ydots - 1;
  374.     sxdots = xdots;  sydots = ydots;
  375.     finalaspectratio = ((float)ydots)/xdots;
  376.  
  377.     calcfracinit();
  378.  
  379.     bitshiftless1 = bitshift - 1;
  380.  
  381.     if (time_to_load)
  382.         goto wait_loop;
  383.  
  384.       if(showfile == 0) {        /* loading an image */
  385.      if (display3d)         /* set up 3D decoding */
  386.         outln = call_line3d;
  387.      else if(filetype >= 1)     /* old .tga format input file */
  388.         outln = outlin16;
  389.      else if(comparegif)        /* debug 50 */
  390.         outln = cmp_line;
  391.      else if(pot16bit) {        /* .pot format input file */
  392.         pot_startdisk();
  393.         outln = pot_line;
  394.         }
  395.      else                /* regular gif/fra input file */
  396.         outln = out_line;
  397.      if(filetype == 0)
  398.         i = funny_glasses_call(gifview);
  399.      else
  400.         i = funny_glasses_call(tgaview);
  401.      if(i == 0)
  402.         buzzer(0);
  403.      else {
  404.         calc_status = -1;
  405.         }
  406.      }
  407.  
  408.       if(showfile == 0) {        /* image has been loaded */
  409.      showfile = 1;
  410.      if (initbatch == 1 && calc_status == 2)
  411.         initbatch = -1; /* flag to finish calc before save */
  412.      if (calc_status == 2) goto try_to_resume;
  413.      }
  414.       else {                /* draw an image */
  415.  
  416. try_to_resume:
  417.  
  418.      diskisactive = 1;        /* flag for disk-video routines */
  419.      if (initsavetime != 0        /* autosave and resumable? */
  420.        && (fractalspecific[fractype].flags&NORESUME) == 0) {
  421.         savebase = readticker(); /* calc's start time */
  422.         saveticks = (long)initsavetime * 1092; /* bios ticks/minute */
  423.         if ((saveticks & 65535) == 0)
  424.            ++saveticks; /* make low word nonzero */
  425.         }
  426.          kbdcount = 30;                 /* ensure that we check the keyboard */
  427.      if ((i = calcfract()) == 0)    /* draw the fractal using "C" */
  428.         buzzer(0); /* finished!! */
  429.          saveticks = 0;         /* turn off autosave timer */
  430.          diskisactive = 0;        /* flag for disk-video routines */
  431.      }
  432.  
  433.     overlay3d = 0;      /* turn off overlay3d */
  434.     display3d = 0;      /* turn off display3d */
  435.  
  436.     zwidth = 0;
  437.  
  438.     if (!keypressed()) {
  439.         flush_screen();
  440.         buzzer(3);
  441.         getakey();
  442.         }
  443.  
  444. wait_loop:
  445.  
  446. for (;;) {
  447.     if (time_to_quit)
  448.          return(0);
  449.     if (time_to_load) {
  450.         strcpy(readname, FileName);
  451.         showfile = 1;
  452.         time_to_load = 0;
  453.         time_to_restart = 0;
  454.         overlay3d = win_overlay3d;
  455.         display3d = win_display3d;
  456.         if (win_load() >= 0) {
  457.             showfile = 0;
  458.             rowcount = 0;
  459.             ytop    = 0;        /* reset the zoom-box */
  460.             ybottom = ydots-1;
  461.             xleft   = 0;
  462.             xright  = xdots-1;
  463.             maxiter = maxit;
  464.             time_to_load = 0;
  465.             time_to_restart = 1;
  466.             if (calc_status == 2) {
  467.                 calc_status = -99;      /* special klooge for restart */
  468.                 }
  469.             }
  470.         win_overlay3d = 0;
  471.         win_display3d = 0;
  472.         }
  473.     if (time_to_save) {
  474.         strcpy(readname, FileName);
  475.         if (readname[0] != 0)
  476.             win_save();
  477.         time_to_save = 0;
  478.         if (calc_status == 2) {
  479.             calc_status = -99;
  480.             time_to_restart = 1;
  481.             }
  482.         }
  483.     if (time_to_print) {
  484.         win_print();
  485.         time_to_print = 0;
  486.         }
  487.     if (time_to_cycle) {
  488.        win_cycle();
  489.        }
  490.     if (time_to_reinit)
  491.          goto reinit;
  492.     if(time_to_restart)
  493.          goto restart;
  494.     getakey();
  495.     }
  496.  
  497. }
  498.  
  499. /* displays differences between current image file and new image */
  500. /* Bert - suggest add this to video.asm */
  501. int cmp_line(unsigned char *pixels, int linelen)
  502. {
  503.    static errcount;
  504.    static FILE *fp = NULL;
  505.    extern int rowcount;
  506.    int row,col;
  507.    int oldcolor;
  508.    char *timestring;
  509.    time_t ltime;
  510.    if(fp == NULL)
  511.       fp = fopen("cmperr",(initbatch)?"a":"w");
  512.    if((row = rowcount++) == 0)
  513.       errcount = 0;
  514.    if(pot16bit) { /* 16 bit info, ignore odd numbered rows */
  515.       if((row & 1) != 0) return(0);
  516.       row >>= 1;
  517.       }
  518.    for(col=0;col<linelen;col++) {
  519.       oldcolor=getcolor(col,row);
  520.       if(oldcolor==pixels[col])
  521.      putcolor(col,row,0);
  522.       else {
  523.      if(oldcolor==0)
  524.         putcolor(col,row,1);
  525.      ++errcount;
  526.      if(initbatch == 0)
  527.         fprintf(fp,"#%5d col %3d row %3d old %3d new %3d\n",
  528.            errcount,col,row,oldcolor,pixels[col]);
  529.      }
  530.       }
  531.    if(row+1 == ydots && initbatch) {
  532.       time(<ime);
  533.       timestring = ctime(<ime);
  534.       timestring[24] = 0; /*clobber newline in time string */
  535.       fprintf(fp,"%s compare to %s has %5d errs\n",timestring,readname,errcount);
  536.       }
  537.    return(0);
  538. }
  539.  
  540. int pot_line(unsigned char *pixels, int linelen)
  541. {
  542.    extern int rowcount;
  543.    int row,col,saverowcount;
  544.    if (rowcount == 0)
  545.       pot_startdisk();
  546.    saverowcount = rowcount;
  547.    row = (rowcount >>= 1);
  548.    if ((saverowcount & 1) != 0) /* odd line */
  549.       row += ydots;
  550.    else             /* even line */
  551.       if (dotmode != 11) /* display the line too */
  552.      out_line(pixels,linelen);
  553.    for (col = 0; col < xdots; ++col)
  554.       writedisk(col+sxoffs,row+syoffs,*(pixels+col));
  555.    rowcount = saverowcount + 1;
  556.    return(0);
  557. }
  558.  
  559. static int call_line3d(unsigned char *pixels, int linelen)
  560. {
  561.    /* this routine exists because line3d might be in an overlay */
  562.    return(line3d(pixels,linelen));
  563. }
  564.  
  565. void win_cmdfiles()   /* convert lpCmdLine into argc, argv */
  566. {
  567. int i, k;
  568. int argc;
  569. char *argv[10];
  570. unsigned char arg[501];   /* max 10 args, 450 chars total */
  571.  
  572. arg[0] = 0;
  573. for (i = 0; i < 10; i++)
  574.    argv[i] = &arg[0];
  575. argc = 1;
  576. strcpy(&arg[1],"winfract.exe");
  577. argv[argc-1] = &arg[1];
  578.  
  579. for (i = 0; i < 460 && win_lpCmdLine[i] != 0; i++)
  580.    arg[20+i] = win_lpCmdLine[i];
  581. arg[20+i] = 0;
  582. arg[21+i] = 0;
  583.  
  584. for (k = 20; arg[k] != 0; k++) {
  585.     while(arg[k] <= ' ' && arg[k] != 0) k++;
  586.     if (arg[k] == 0) break;
  587.     if (argc >= 10) break;
  588.     argc++;
  589.     argv[argc-1] = &arg[k];
  590.     while(arg[k] > ' ')k++;
  591.     arg[k] = 0;
  592.     }
  593.  
  594. cmdfiles(argc,argv);
  595.  
  596. }
  597.